Axios.defaults.baseURL = project + '/onlineArchive/transfer/customer';

let main ={
    el:"#app",
    data:function() {
        return {
            loading_1:false,
            loading_2:false,
            loading_3:false,
            activeName: 'first',
            archivalStatus:[],
            archivalType:[],
            incomingWay:[],
            customerTobeSortedSearch:{
                pagination:{
                    pageNum: 1,
                    pageSize: 10,
                    total:0,
                },
                isSimple:true,
                applicationDate:[],
                loanTime:[],
                applicationNo:'',
                customerName:'',
                productName:'',
                incomingWay:'',
                insuredName:'',
                archivalType:'',
                archivalStatus:'',
                keyword:''
            },
            customerTobeSortedList: [],
            archivePageNumberDialogVisible:false,
            toBeSortedTransferIds:[],
            customerTransferedDeputySearch:{
                pagination:{
                    pageNum: 1,
                    pageSize: 10,
                    total:0,
                },
                applicationDate:[],
                loanTime:[],
                applicationNo:'',
                customerName:'',
                productName:'',
                incomingWay:'',
                insuredName:'',
                archivalType:'',
                archivalStatus:'',
                transferDeputyTime:[],
                keyword:''
            },
            customerTransferedDeputyList:[],
            customerDeputyFallbackSearch:{
                pagination:{
                    pageNum: 1,
                    pageSize: 10,
                    total:0,
                },
                applicationDate:[],
                loanTime:[],
                applicationNo:'',
                customerName:'',
                productName:'',
                incomingWay:'',
                insuredName:'',
                archivalType:'',
                archivalStatus:'',
                transferDeputyTime:[],
                keyword:''
            },
            customerDeputyFallbackList:[],
            fallBackTransferIds:[],
            deputyFallbackIds:[],
            searchArea:{
                toBeSortedTable:{
                    height:40,
                    isSimple:true
                },
                transferedDeputyTable:{
                    height:40,
                    isSimple:true
                },
                fallbackTable:{
                    height:40,
                    isSimple:true
                }
            },
        }
    },
    beforeMount:function(){
        this.init();
    },
    computed: {
        // 计算属性的 getter
        tableHeight: function () {
            let height = window.parent.document.getElementById('content-main').clientHeight;
            let that = this;
            return {
                toBeSortedTable:height - that.searchArea.toBeSortedTable.height- 125,
                transferedDeputyTable:height - that.searchArea.transferedDeputyTable.height- 125,
                fallbackTable:height - that.searchArea.fallbackTable.height- 125
            }
        }
    },
    methods:{
        /**
         * 重置查询条件
         * @param table
         */
        resetSearch:function(table){
            if (table == 'toBeSortedTable') {
                this.customerTobeSortedSearch = {
                    pagination:{
                        pageNum: 1,
                            pageSize: 10,
                            total:0,
                    },
                    isSimple:true,
                    applicationDate:[],
                    loanTime:[],
                    applicationNo:'',
                    customerName:'',
                    productName:'',
                    incomingWay:'',
                    insuredName:'',
                    archivalType:'',
                    archivalStatus:'',
                    keyword:''
                };
                this.initToBeSortedPageList();
                return ;
            }
            else if (table == 'transferedDeputyTable'){
                this.customerTransferedDeputySearch = {
                    pagination:{
                        pageNum: 1,
                            pageSize: 10,
                            total:0,
                    },
                    isSimple:true,
                    applicationDate:[],
                        loanTime:[],
                        applicationNo:'',
                        customerName:'',
                        productName:'',
                        incomingWay:'',
                        insuredName:'',
                        archivalType:'',
                        archivalStatus:'',
                        transferDeputyTime:[],
                        keyword:''
                },
                    this.initTransferedDeputyPageList();
                    return ;
            }
            else if (table == 'fallbackTable'){
                this.customerDeputyFallbackSearch = {
                    pagination:{
                        pageNum: 1,
                            pageSize: 10,
                            total:0,
                    },
                    isSimple:true,
                    applicationDate:[],
                        loanTime:[],
                        applicationNo:'',
                        customerName:'',
                        productName:'',
                        incomingWay:'',
                        insuredName:'',
                        archivalType:'',
                        archivalStatus:'',
                        transferDeputyTime:[],
                        keyword:''
                },
                    this.initDeputyFallbackPageList();
                    return ;
            }
            else {
                return;
            }
        },
        /**
         * 展开  收缩查询区域
         * @param table
         */
        showclick:function(table){
            this.searchArea[table].isSimple = !this.searchArea[table].isSimple;
            let that =this;
            setTimeout(function () {
                that.searchArea[table].height = window.document.getElementById(table).clientHeight ;
            },500)
        },
        /**
         * 页面渲染时加载数据
         */
        init:function(){
            let that = this;
            axios.all([getArchivalStatusList(),getArchivalTypeList(),getIncomingWayList()])
                .then(axios.spread(function (archivalStatus,archivalType,incomingWay) {
                    that.archivalStatus = archivalStatus.data.data;
                    that.archivalType = archivalType.data.data;
                    that.incomingWay = incomingWay.data.data;
                })).then(function () {
                that.initToBeSortedPageList();
            });
        },

        /**
         *获取待整理数据
         */
        getToBeSortedPageList:function(){
            let that = this;
            that.loading_1 = true;
            Axios({
                method: 'post',
                url: '/toBeSorted/pageList',
                data: that.customerTobeSortedSearch
            })
            .then(function (response) {
                that.loading_1 = false;
                if (response.code != 0){
                    noticeDataRequestFailure(that);
                    return;
                }
                that.customerTobeSortedList = response.data.list;
                that.customerTobeSortedSearch.pagination.total = response.data.total;
            })
            .catch(function (error) {
                noticeFailure(that);
                that.loading_1 = false;
            });
        },
        /**
         * 初始化待整理数据列表，（加载第一页数据）
         */
        initToBeSortedPageList:function(){
            this.toBeSortedTablePageNumChange(1);
        },
        /**
         * 待整理列表 ，页码改变时触发
         * @param pageNum
         */
        toBeSortedTablePageNumChange:function(pageNum){
            this.customerTobeSortedSearch.pagination.pageNum = pageNum;
            this.getToBeSortedPageList();
        },
        /**
         * 待整理数据列表，每页条数改变时触发
         * @param pageSize
         */
        toBeSortedTablePageSizeChange:function(pageSize){
            this.customerTobeSortedSearch.pagination.pageNum = 1;
            this.customerTobeSortedSearch.pagination.pageSize = pageSize;
            this.getToBeSortedPageList();
        },
        /**
         *获取已移交副理数据
         */
        getTransferedDeputyPageList:function(){
            let that = this;
            that.loading_2 = true;
            Axios({
                method: 'post',
                url: '/transferedDeputy/pageList',
                data: that.customerTransferedDeputySearch
            })
                .then(function (response) {
                    if (response.code != 0){
                        noticeDataRequestFailure(that);
                        that.loading_2 = false;
                        return;
                    }
                    that.customerTransferedDeputyList = response.data.list;
                    that.customerTransferedDeputySearch.pagination.total = response.data.total;
                    that.loading_2 = false;
                })
                .catch(function (error) {
                    noticeFailure(that);
                });
        },
        /**
         * 初始化已移交副理数据列表，（加载第一页数据）
         */
        initTransferedDeputyPageList:function(){
            this.transferedDeputyPageNumChange(1);
        },
        /**
         * 已移交副理数据列表 ，翻页，跳页
         * @param pageNum
         */
        transferedDeputyPageNumChange:function(pageNum){
            this.customerTransferedDeputySearch.pagination.pageNum = pageNum;
            this.getTransferedDeputyPageList();
        },
        /**
         * 已移交副理数据列表 ，每页条数改变时触发
         * @param pageNum
         */
        transferedDeputyPageSizeChange:function(pageSize){
            this.customerTransferedDeputySearch.pagination.pageNum = 1;
            this.customerTransferedDeputySearch.pagination.pageSize = pageSize;
            this.initTransferedDeputyPageList();
        },
        /**
         *获取副理回退数据
         */
        getDeputyFallbackPageList:function(){
            let that = this;
            that.loading_3 = true;
            Axios({
                method: 'post',
                url: '/deputyFallback/pageList',
                data: that.customerDeputyFallbackSearch
            })
                .then(function (response) {
                    if (response.code != 0){
                        noticeDataRequestFailure(that);
                        that.loading_3 = false;
                        return;
                    }
                    that.customerDeputyFallbackList = response.data.list;
                    that.customerDeputyFallbackSearch.pagination.total = response.data.total;
                    that.loading_3 = false;
                })
                .catch(function (error) {
                    noticeFailure(that);
                    that.loading_3 = false;
                });
        },
        /**
         * 初始化副理回退数据列表，（加载第一页数据）
         */
        initDeputyFallbackPageList:function(){
            this.deputyFallbackTablePageNumChange(1);
        },
        /**
         * 副理回退列表 ，页码改变时触发
         * @param pageNum
         */
        deputyFallbackTablePageNumChange:function(pageNum){
            this.customerDeputyFallbackSearch.pagination.pageNum = pageNum;
            this.getDeputyFallbackPageList();
        },
        /**
         * 副理回退数据列表，每页条数改变时触发
         * @param pageSize
         */
        deputyFallbackTablePageSizeChange:function(pageSize){
            this.customerDeputyFallbackSearch.pagination.pageNum = 1;
            this.customerDeputyFallbackSearch.pagination.pageSize = pageSize;
            this.getDeputyFallbackPageList();
        },
        /**
         * 日期列格式化
         * @param row
         * @param column
         * @param cellValue
         * @param index
         */
        dateTimeFormatter:function(row, column, cellValue, index){
            return dateFormatter(cellValue);
        },
        /**
         * 是否格式化
         * @param row
         * @param column
         * @param cellValue
         * @param index
         */
        booleanFormatter:function(row,column,cellValue,index){
            return booleanFormatter(cellValue);
        },
        /**
         * 档案状态格式化
         * @param row
         * @param column
         * @param cellValue
         * @param index
         */
        archivalStatusFormatter:function(row,column,cellValue,index){
            for(let i = 0 ; i < this.archivalStatus.length ; i++){
                if (this.archivalStatus[i].code == cellValue){
                    return this.archivalStatus[i].description;
                }
            }
            return "";
        },
        /**
         * 档案类型格式化
         * @param row
         * @param column
         * @param cellValue
         * @param index
         * @returns {string|*}
         */
        archivalTypeFormatter:function(row,column,cellValue,index){
            for(let i = 0 ; i < this.archivalType.length ; i++){
                if (this.archivalType[i].code == cellValue){
                    return this.archivalType[i].value;
                }
            }
            return "";
        },
        /**
         * 进件方式格式化
         * @param row
         * @param column
         * @param cellValue
         * @param index
         * @returns {string|*}
         */
        incomingWayFormatter:function(row, column, cellValue, index){
            for(let i = 0 ; i < this.incomingWay.length ; i++){
                if (this.incomingWay[i].code == cellValue){
                    return this.incomingWay[i].value;
                }
            }
            return "";
        },
        /**
         * 待整理数据表格复选框选择数据
         * @param selection
         */
        toBeSortedTableSelectionChange:function(selection){
            this.toBeSortedTransferIds = selection.map(function(x){return x.id});
        },
        /**
         * 待整理数据移交
         */
        toBeSortedTransfer:function(){
            let that = this;
            if (that.toBeSortedTransferIds.length == 0){
                noticeWarning(that,'还未选择档案');
                return;
            }
            this.$confirm('本次移交档案：'+ that.toBeSortedTransferIds.length +'份，请与实物档案核对是否一致！', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'info'
            }).then(function() {
                Axios({
                    url:'/transfer',
                    data:that.toBeSortedTransferIds,
                    method:'post',
                }).then(function (response) {
                    if (response.code != 0){
                        noticeFailure(that);
                        return;
                    }
                    that.initToBeSortedPageList();
                    noticeSuccess(that);
                }).catch(function (error) {
                    noticeDataRequestFailure(that);
                })
            });
        },
        /**
         * 副理回退数据表格复选框选择数据
         * @param selection
         */
        fallbackTableSelectionChange:function(selection){
            this.fallBackTransferIds = selection.map(function(x){return x.id});
        },
        /**
         * 副理回退移交
         */
        fallbackTransfer:function(){
            let that = this;
            if (that.fallBackTransferIds.length == 0){
                noticeWarning(that,'还未选择档案');
                return;
            }
            this.$confirm('本次移交档案：'+ that.fallBackTransferIds.length +'份，请与实物档案核对是否一致！', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'info'
            }).then(function() {
                Axios({
                    url:'/transfer',
                    data:that.fallBackTransferIds,
                    method:'post',
                }).then(function (response) {
                    if (response.code != 0){
                        noticeFailure(that);
                        return;
                    }
                    that.initDeputyFallbackPageList();
                    noticeSuccess(that);
                }).catch(function (error) {
                    noticeDataRequestFailure(that);
                })
            });
        },
        /**
         * 点击tab页切换时执行
         * @param tab
         */
        tabClick:function(tab){
            if (tab.name == 'first') {
                this.initToBeSortedPageList();
                return;
            }
            if (tab.name == 'second') {
                this.initTransferedDeputyPageList();
                return;
            }
            if (tab.name == 'third') {
                this.initDeputyFallbackPageList();
                return;
            }
        }

    }
}
new Vue(main);